package com.visitorspecials.tankbattle.server;

import java.util.ArrayList;

import com.visitorspecials.tankbattle.*;

public class HelperFuncs
{
	public static float degreesToRadians(float degrees)
	{
		return degrees * (float) Math.PI / 180.0f;
	}

	public static float radiansToDegrees(float radians)
	{
		return radians * 180.0f / (float) Math.PI;
	}
	
	public static float averageArray(float[] values)
	{
		float sum = 0;
		int count = 0;
		
		for(float f : values)
		{
			count++;
			sum += f;
		}
		
		return sum / count;
	}

	public static ArrayList<Sprite> parseStringToSprites(String str)
	{
		ArrayList<Sprite> al = new ArrayList<Sprite>();

		for (String s : str.split("::"))
		{
			if (s.length() > 0)
				al.add(parseStringToSprite(s));
		}

		return al;
	}

	public static Sprite parseStringToSprite(String str)
	{
		String[] params = str.split(":");
		return new Sprite(params[0], S2F(params[1]), S2F(params[2]),
				S2F(params[3]), S2F(params[4]), S2F(params[5]), S2F(params[6]), S2F(params[7]), S2F(params[8]));
	}

	public static float S2F(String s)
	{
		return Float.parseFloat(s);
	}

	/*
	 * public static float DistanceBetween(Sprite sprite1, Sprite sprite2) {
	 * double xdiff = (double)(sprite1.getX() - sprite2.getX()); double ydiff =
	 * (double)(sprite1.getY() - sprite2.getY());
	 * 
	 * return (float)Math.sqrt(xdiff * xdiff + ydiff * ydiff); }
	 */
}
